package cn.tedu.eb_film.controller;

import cn.tedu.eb_film.pojo.dto.CinemaFormDTO;
import cn.tedu.eb_film.pojo.page.CinemaPagination;
import cn.tedu.eb_film.pojo.dto.CinemaAddNewDTO;
import cn.tedu.eb_film.pojo.dto.CinemaUpdateDTO;
import cn.tedu.eb_film.pojo.entity.CinemaList;
import cn.tedu.eb_film.pojo.vo.CinemaListVO;
import cn.tedu.eb_film.pojo.vo.CinemaServiceVO;
import cn.tedu.eb_film.pojo.vo.CinemaStandardVO;
import cn.tedu.eb_film.pojo.vo.SearchCinemaVo;
import cn.tedu.eb_film.service.CinemaService;
import cn.tedu.eb_film.utils.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 电影院控制类
 *
 * @author ライナー・ロンテ
 * @since 2023/3/18 14:24
 */
@Slf4j
@RestController
@Api(tags = "电影院管理模块")
@RequestMapping("cinema")
public class CinemaController {
    @Autowired
    private CinemaService cinemaService;

    @PostMapping("addNew")
    @ApiOperation("添加电影院")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> addNew(@RequestBody CinemaFormDTO addNewDTO){
        log.debug("开始处理新增电影院数据");
        System.out.println(addNewDTO);
        cinemaService.addNew(addNewDTO);
        return JsonResult.ok();
    }

    @PostMapping("addNews")
    @ApiOperation("批量添加电影院数据")
    @ApiOperationSupport(order = 110)
    public JsonResult<Void> addNews(@RequestBody List<CinemaAddNewDTO> addNewDTOs) {
        log.debug("开始处理新增电影院数据");
        cinemaService.addNews(addNewDTOs);
        return JsonResult.ok();
    }

    @PostMapping("{id}/delete")
    @ApiOperation("根据id删除电影院数据")
    @ApiOperationSupport(order = 200)
    public JsonResult<Void> deleteById(@PathVariable Long id) {
        log.debug("开始根据id删除电影院数据");
        cinemaService.deleteById(id);
        return JsonResult.ok();
    }

    @PostMapping("deletes")
    @ApiOperation("批量删除数据")
    @ApiOperationSupport(order = 210)
    public JsonResult<Void> deleteById(@RequestBody List<Long> ids) {
        log.debug("开始根据ids删除电影院数据");
        cinemaService.deleteByIds(ids);
        return JsonResult.ok();
    }

    @GetMapping("{id}/get")
    @ApiOperation("根据id获取数据")
    @ApiOperationSupport(order = 300)
    public JsonResult<CinemaStandardVO> get(@PathVariable Long id) {
        log.debug("开始根据id查询数据");
        final CinemaStandardVO cinemaStandardVO = cinemaService.getCinemaStandardVOById(id);
        return JsonResult.ok(cinemaStandardVO);
    }

    @GetMapping("{id}/getService")
    @ApiOperation("根据id获取服务信息")
    @ApiOperationSupport(order = 300)
    public JsonResult<CinemaServiceVO> getService(@PathVariable Long id) {
        log.debug("开始根据id查询数据");
        final CinemaServiceVO cinemaServiceVO = cinemaService.getCinemaServiceVOById(id);
        return JsonResult.ok(cinemaServiceVO);
    }


    @GetMapping("list")
    @ApiOperation("查询电影院数据列表")
    @ApiOperationSupport(order = 310)
    public JsonResult<List<CinemaList>> list() {
        log.debug("开始根据id查询数据");
        final List<CinemaList> list = cinemaService.list();
        return JsonResult.ok(list);
    }

    @PostMapping("pageList")
    @ApiOperation("分页查询电影院数据")
    @ApiOperationSupport(order = 311)
    public JsonResult<CinemaListVO> list(@RequestBody CinemaPagination pagination) {
        log.debug("开始根据id查询数据");
        final CinemaListVO list = cinemaService.pageList(pagination);
        return JsonResult.ok(list);
    }

    @PostMapping("search")
    @ApiOperation("查询电影院数据列表")
    @ApiOperationSupport(order = 315)
    public JsonResult<List<CinemaList>> search() {
        log.debug("开始根据id查询数据");
        final List<CinemaList> list = cinemaService.list();
        return JsonResult.ok(list);
    }

    @PostMapping("upload")
    @ApiOperation("更新电影院数据")
    @ApiOperationSupport(order = 400)
    public JsonResult<Void> upload(@RequestBody CinemaUpdateDTO cinemaUpdateDTO) {
        log.debug("开始根据id查询数据");
        cinemaService.update(cinemaUpdateDTO);
        return JsonResult.ok();
    }

    @PostMapping("/{id}/enable")
    @ApiOperation("启用电影院数据")
    @ApiOperationSupport(order = 410)
    public JsonResult<Void> enable(@PathVariable Long id) {
        log.debug("开始根据id查询数据");
        cinemaService.enable(id);
        return JsonResult.ok();
    }

    @PostMapping("/{id}/disable")
    @ApiOperation("禁用电影院数据")
    @ApiOperationSupport(order = 411)
    public JsonResult<Void> disable(@PathVariable Long id) {
        log.debug("开始根据id查询数据");
        cinemaService.disable(id);
        return JsonResult.ok();
    }

    @PostMapping("edit")
    @ApiOperation("编辑电影院")
    @ApiOperationSupport(order = 430)
    public JsonResult<Void> edit(@RequestBody CinemaFormDTO editDto){
        log.debug("开始处理编辑电影院");
        cinemaService.edit(editDto);
        return JsonResult.ok();
    }

    @PostMapping("/getCinema")
    @ApiOperation("根据电影院名字模糊查询")
    @ApiOperationSupport(order = 412)
    public JsonResult<List<SearchCinemaVo>> getCinema(String name) {
        List<SearchCinemaVo> list = cinemaService.getCinema(name);
        log.info("查询出参数{}",list);
        return JsonResult.ok(list);
    }

    @GetMapping("/loadCinema")
    @ApiOperation("获取电影院列表")
    @ApiOperationSupport(order = 413)
    public JsonResult <List<SearchCinemaVo>> loadCinema(){
        List<SearchCinemaVo> list = cinemaService.loadCinema();
        return JsonResult.ok(list);
    }

    @PostMapping("/getCinemaByAddress")
    @ApiOperation("通过地址获取电影院")
    @ApiOperationSupport(order = 414)
    public JsonResult <List<SearchCinemaVo>> getCinemaByAddress(String address){
        List<SearchCinemaVo> list = cinemaService.getCinemaByAddress(address);
        return JsonResult.ok(list);
    }

    @GetMapping("/Imax")
    @ApiOperation("获取imax厅")
    @ApiOperationSupport(order = 415)
    public JsonResult <List<SearchCinemaVo>> Imax(){
        List<SearchCinemaVo> list = cinemaService.Imax();
        return JsonResult.ok(list);
    }

    @GetMapping("/normal")
    @ApiOperation("获取normal厅")
    @ApiOperationSupport(order = 415)
    public JsonResult <List<SearchCinemaVo>> normal(){
        List<SearchCinemaVo> list = cinemaService.normal();
        return JsonResult.ok(list);
    }
}
